package com.itheima.dianming.controller;

import com.itheima.dianming.aop.HasAuth;
import com.itheima.dianming.pojo.domain.AskLog;
import com.itheima.dianming.service.AskLogService;
import com.itheima.dianming.pojo.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


@RestController
@RequestMapping("/asklog")
public class AskLogController {

    @Autowired
    private AskLogService askLogService;

    /**
     * 课堂提问日志记录
     * @param askLog 提问日志对象
     * @return R
     */
    @PostMapping
    @HasAuth("ROLE_ADMIN")
    public R addLog(@RequestBody AskLog askLog){
        askLog.setAskTime(new Date());
        boolean save = askLogService.save(askLog);
        return R.onflag(save);
    }
}
